package visiopuce.ui.providers;

import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;

import visiopuce.objets.GeneNcbi;

public class GeneTableLabelProvider extends ColumnLabelProvider implements IColorProvider {

	private int colindex;

	/** Constructeur privé */
	public GeneTableLabelProvider(int colindex) {
		this.colindex = colindex;
	}

	@Override
	public String getText(Object element) {
		String result = null;
		GeneNcbi gene = (GeneNcbi) element;

		switch (colindex) {
		case 0:
			result = gene.getSymbol();
			break;
		case 1:
			result = gene.getOrientation();
			break;
		case 2: {
			result = gene.getType();
			break;
		}
		case 3:
			result = gene.getDescription();
			break;
		case 4: {
			if (gene.getDisorderMimnb() != null) {
				String[] noms = gene.getDisorderMimname().split("\\|");
				int i = 0;
				result = "";
				for (String nom : noms) {
					if (nom != null && !nom.isEmpty() && !nom.equals("null")) {
						result += noms[i] + "-";
					}
					i++;
				}

			} else {
				result = "-";
			}
			break;
		}
		case 5: {
			if (gene.getTumorSupp().equals("Dominant")) {
				result = "Préd. cancer (D.)";
			} else if (gene.getTumorSupp().equals("Récessif")) {
				result = "Préd. cancer (R.)";
			} else {
				result = "-";
			}
			break;
		}
		case 6: {
			if (gene.getRm().equals("ASD Implicated")) {
				result = "Impliqué TED";
			} else if (gene.getRm().equals("id")) {
				result = "Impliqué RM";
			} else if (gene.getRm().equals("ASD candidate")) {
				result = "Candidat TED";
			} else if (gene.getRm().equals("déf.int")) {
				result = "Impliqués DI";
			} else {
				result = "-";
			}
			break;
		}
		case 7: {
			if (gene.getMimnb() != null) {
				result = gene.getMimnb().toString();
			} else {
				result = "-";
			}
			break;
		}
		case 8:
			result = "Genecards";
			break;
		case 9:
			result = "Ensembl";
			break;
		case 10:
			result = "Pubmed";
			break;

		case 11:
			result = "NCBI Entrez";
			break;

		case 12:
			result = "DGV";
			break;

		case 13:
			result = "UCSC";
			break;
		}

		return result.trim();
	}

	@Override
	public String getToolTipText(Object element) {
		String result = null;
		GeneNcbi gene = (GeneNcbi) element;

		switch (colindex) {
		case 0:
			result = gene.getSymbol();
			break;
		case 1:
			result = gene.getOrientation();
			break;
		case 2: {
			result = gene.getType();
			break;
		}
		case 3:
			result = gene.getDescription();
			break;
		case 4: {
			if (gene.getDisorderMimnb() != null) {
				String[] noms = gene.getDisorderMimname().split("\\|");
				int i = 0;
				result = "";
				for (String nom : noms) {
					if (nom != null && !nom.isEmpty() && !nom.equals("null")) {
						result += noms[i] + "-";
					}
					i++;
				}

			} else {
				result = "-";
			}
			break;
		}
		case 5: {
			if (gene.getTumorSupp().equals("Dominant")) {
				result = "Prédisposition aux cancers (Dominant)";
			} else if (gene.getTumorSupp().equals("Récessif")) {
				result = "Prédisposition aux cancers (Récessif)";
			} else {
				result = "-";
			}
			break;
		}
		case 6: {
			if (gene.getRm().equals("ASD Implicated")) {
				result = "Impliqué dans les troubles envahissants du développement (Autisme)";
			} else if (gene.getRm().equals("id")) {
				result = "Impliqué dans le retard mental";
			} else if (gene.getRm().equals("ASD candidate")) {
				result = "Gène candidat pour être impliqué dans les troubles envahissants du développement (Autisme)";
			} else if (gene.getRm().equals("déf.int")) {
				result = "Gènes préalablement impliqués dans la déficience intellectuelle (projet NGS MR)";
			} else {
				result = "-";
			}
			break;
		}
		case 7: {
			if (gene.getMimnb() != null) {
				result = gene.getMimnb().toString();
			} else {
				result = "-";
			}
			break;
		}
		case 8:
			result = "Lien vers Genecards";
			break;
		case 9:
			result = "Lien vers Ensembl";
			break;
		case 10:
			result = "Lien vers Pubmed";
			break;

		case 11:
			result = "Lien vers NCBI Entrez";
			break;

		case 12:
			result = "Lien vers DGV";
			break;

		case 13:
			result = "Lien vers UCSC";
			break;
		}

		return result.trim();

	}

	@Override
	public Color getBackground(Object element) {
		GeneNcbi geneNcbi = (GeneNcbi) element;
		Color color = new Color(Display.getCurrent(), 255, 255, 255);
		if (geneNcbi.getTumorSupp().trim().equals("Dominant") || geneNcbi.getTumorSupp().trim().equals("Récessif")) {
			color = new Color(Display.getCurrent(), 255, 0, 0);
		}
		if (geneNcbi.getRm().trim().equals("ASD Implicated")) {
			color = new Color(Display.getCurrent(), 186, 0, 255);

		} else if (geneNcbi.getRm().trim().equals("id")) {
			color = new Color(Display.getCurrent(), 186, 0, 255);

		} else if (geneNcbi.getRm().trim().equals("ASD candidate")) {
			color = new Color(Display.getCurrent(), 186, 0, 255);

		} else if (geneNcbi.getRm().trim().equals("déf.int")) {
			color = new Color(Display.getCurrent(), 186, 0, 255);
		}
		if (geneNcbi.getDisorderMimnb() != null && !geneNcbi.getDisorderMimnb().isEmpty()) {
			color = new Color(Display.getCurrent(), 255, 198, 108);
		}
		return color;
	}

	@Override
	public Color getForeground(Object element) {
		Color color;
		if (colindex == 0 || colindex == 4 || colindex >= 7) {
			color = new Color(Display.getCurrent(), 24, 80, 208);
		} else {
			color = new Color(Display.getCurrent(), 0, 0, 0);
		}
		return color;
	}
}
